package com.kcsj.demo.Controller;

import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
public class LoginController {
    @PostMapping("/login")
    public String login(@RequestParam("username") String username,
                        @RequestParam("password") String password,
                        Map<String,Object> map, HttpSession session){

        if (!StringUtils.isEmptyOrWhitespaceOnly(username) &&( "123456".equals(password) || "651343119".equals(password))){
            session.setAttribute("loginUser",username);
            //用户名不为空且密码正确
            return "index";
        }
        else {
            map.put("msg","密钥有误");
            return "index";
        }
    }
}
